package com.tlgen.coopera.runner;

import com.tlgen.coopera.model.BeatRegistryServer;
import lombok.Data;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/*
 *@title MyDelayTask
 *@description
 *@author ta151486
 *@version 1.0
 *@create 2023/12/14 9:32
 */
@Data
public class MyDelayTask implements Delayed {

    private BeatRegistryServer beatRegistryServer;

    private long delayTime;

    public MyDelayTask(BeatRegistryServer beatRegistryServer, long delayTime) {
        this.beatRegistryServer = beatRegistryServer;
        this.delayTime = System.currentTimeMillis() + delayTime;
    }

    // 获取任务剩余时间
    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(delayTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return Long.compare(delayTime, ((MyDelayTask) o).delayTime);
    }

}
